<template>
  <h1>账户信息</h1>
  <van-divider />
  <p>地址：{{ address }}</p>
  <p>
    私钥：0x7da38f79caa69a4840224d1dc39fc492d4b132d3de4da224f56351b340becdf8
  </p>
  <p>余额：{{ mount }}</p>
</template>

<script setup>
import { ref } from 'vue'
import Web3 from 'web3'
// 实例化
const web3 = new Web3(
  Web3.givenProvider ||
    'wss://linea-sepolia.infura.io/ws/v3/ba881713e5e54566bafd884b05f41459'
)

// 创建账户
// const account = web3.eth.accounts.create("123")
// 只能执行一次，就创建一个新账号
// console.log(account.address)
// console.log(account.privateKey)

const address = ref('0xA41d90c1c3b96b7031A41187A88f7529460f62de')

// 获取余额
const mount = ref(-1)
web3.eth.getBalance(address.value).then(res => {
  console.log('---res---', res)
  mount.value = res
})

// 单位转化
const num1 = Web3.utils.toWei('0.03', 'ether')
const num2 = web3.utils.toWei('0.3', 'ether')
const num3 = Web3.utils.fromWei('3000000000000000', 'ether')
const num4 = web3.utils.fromWei('30000000000000000', 'ether')
console.log('---num1---num2---num3---num4', num1, num2, num3, num4)
</script>
